<?php
function is_valid_email($email)
{
	if(preg_match("/[a-zA-Z0-9-.+]+@[a-zA-Z0-9-]+.[a-zA-Z]+/", $email) > 0)
		return true;
	else
		return false;
}
$cparams =& JComponentHelper::getParams('com_media');
$app = JFactory::getApplication();
$templateDir = JURI::base() . 'templates/' . $app->getTemplate();
$sendemail=false;
if($_POST['submit'])
{
	$sendemail = true;
	if(!is_valid_email($_POST['from']))
	{
		$error[]['text']=JText::_('PLEASE INPUT EMAIL');
		$sendemail=false;
	}
	if($_POST['name']=="")
	{
		$error[]['text']=JText::_('PLEASE INPUT NAME');
		$sendemail=false;
	}
	if($_POST['age']=="")
	{
		$error[]['text']=JText::_('PLEASE INPUT AGE');
		$sendemail=false;
	}
	if($_POST['level']=="")
	{
		$error[]['text']=JText::_('PLEASE INPUT ENGLISH LEVEL');
		$sendemail=false;
	}
}
if($sendemail)
{
	$lang =& JFactory::getLanguage();
	$locales = $lang->getLocale();
	if(strstr($locales[0],'vi'))
	{
		$language="vi";
	}
	else
	{
		$language="en";
	}
	$template = JPATH_ROOT.'/emails/'.$language.'/suggest_file.php';
	$body=file_get_contents($template);
	$template_thanks = JPATH_ROOT.'/emails/'.$language.'/suggest_file_thanks.php';
	$body_thanks=file_get_contents($template_thanks);
	
	$mailfrom = $_POST['from'];
	$fromname = $_POST['name'];
	$email = "anhcuongtv@gmail.com";
	$subject = "File Suggestion";
	$body=str_replace("{name}",$_POST['name'] , $body);
	$body=str_replace("{age}",$_POST['age'] , $body);
	$body=str_replace("{english_level}",$_POST['level'] , $body);
	$body=str_replace("{learn}",$_POST['listen'] , $body);
	$body=str_replace("{help}",$_POST['help'] , $body);
	$body=str_replace("{comment}",$_POST['comment'] , $body);
	$body=str_replace("{year}",date("Y"), $body);
	$body_thanks=str_replace("{year}",date("Y"), $body_thanks);
	JUtility::sendMail($mailfrom, $fromname, $email, $subject, $body,1);
	JUtility::sendMail($email, $fromname, $mailfrom, $subject, $body_thanks,1);
	$error[]['text']=JText::_('EMAIL HAS BEEN SENT');
} 
?>
<script type="text/javascript">
function check_text_onfocus(obj)
{ if(obj.value == obj.defaultValue)obj.value = '';}
function check_text_onblur(obj){
if(obj.value=='')
obj.value = obj.defaultValue;
}
</script>

<link rel="stylesheet" type="text/css" href="<?php echo $templateDir; ?>/css/vita_subpages.css" media="screen" />
<div class="content">
                        <div class="innerContent"> 
                            <h2><span><span><?php echo JText::_('SUGGEST FILE');?></span></span></h2>
                            <div class="fckDefault">
                              <a href="<?php echo JRoute::_('index.php?option=com_content&view=article&id=47&Itemid=54');?>" title="<?php echo JText::_('RETURN VITA');?>" class="lnkReturn"><img src="<?php echo $templateDir; ?>/images/vita/dummy.gif" alt="Return to Vita" class="uiIcon initIcon-09"/><span><?php echo JText::_('RETURN VITA');?></span></a> <br/>
                              <div id="infoBlock"><?php echo JText::_('SUGGEST FILE INFO');?>
                              </div>
                              <form id="suggestForm" name="suggestForm" method="post">
                              <table class="contentForm">
                                <tr>
                                  <th><?php echo JText::_('EMAIL TEMPLATE');?></th>
                                </tr>
                                <?php
                                if(count($error)>0)
                                {
                                ?>
                                <tr>
                                	<td>
                                	<font color="red">
                                	<?php 
                                	foreach($error as $detail_err)
                                	{
                                		echo $detail_err['text'].'<br/>';
                                	}
                                	?>
                                	</font>
                                	</td>
                                </tr>
                                <?php
                                } 
                                ?>
                                <tr>
                                    <td>
                                        <?php echo JText::_('TO');?>: suggestion@taylormade-elt.com<br/>
                                        <?php echo JText::_('FROM');?>: <input name="from" type='text' size="35" value='<?php echo JText::_('PLEASE INPUT EMAIL');?>' onfocus='javascript:check_text_onfocus(this)' onblur='javascript:check_text_onblur(this)' style="border:none; color: #bbb;" />
                                        <br/>                                                                      
                                        <?php echo JText::_('SUBJECT');?>: <?php echo JText::_('SUGGEST FILE');?><br/><br/>
                                        
                                        <?php echo JText::_('NAME');?>: <input name="name" type='text' size="35" value='<?php echo JText::_('PLEASE INPUT NAME');?>' onfocus='javascript:check_text_onfocus(this)' onblur='javascript:check_text_onblur(this)' style="border:none; color: #bbb;" />
                                        <br/>                                        
                                        <?php echo JText::_('AGE');?>: <input name="age" type='text' size="35" value='<?php echo JText::_('PLEASE INPUT AGE');?>' onfocus='javascript:check_text_onfocus(this)' onblur='javascript:check_text_onblur(this)' style="border:none; color: #bbb;" />
                                        <br/>                                        
                                        <?php echo JText::_('ENGLISH LEVEL');?>: <input name="level" type='text' size="35" value='<?php echo JText::_('PLEASE INPUT ENGLISH LEVEL');?>' onfocus='javascript:check_text_onfocus(this)' onblur='javascript:check_text_onblur(this)' style="border:none; color: #bbb;" />
                                        <br/><br/> 
                                        
                                        <?php echo JText::_('LEARN ABOUT');?>: <input name="listen" type='text' size="35" value='' onfocus='javascript:check_text_onfocus(this)' onblur='javascript:check_text_onblur(this)' style="border:none; color: #bbb;" />
                                        <br/><br/>         
                                        <?php echo JText::_('HELP ABOUT');?>: <input name="help" type='text' size="35" value='' onfocus='javascript:check_text_onfocus(this)' onblur='javascript:check_text_onblur(this)' style="border:none; color: #bbb;" />
                                        <br/><br/>  
                                        <?php echo JText::_('ELEMENT SUGGEST FILE');?>:<br/><textarea name="comment" id="comment" rows="6" cols="100" onfocus='javascript:check_text_onfocus(this)' onblur='javascript:check_text_onblur(this)' style="border:none; color: #bbb;"><?php echo JText::_('PLEASE INPUT COMMENT');?></textarea>
                                        <br/><br/>                                                    
                                    </td>
                                </tr>
                                
                                <tr>
                                    <td class="sendForm"><input id="submit" name="submit" type="submit" value="<?php echo JText::_('SEND');?>" /></td>
                                </tr>
                              </table>
                              </form>
                            </div>
                        </div>
                </div>

                                        
                
                 
                                                
               
